/*
* Copyright © Shanghai Awinic Technology Co., Ltd. 2020-2020. All rights reserved.
* Description: The header file of the i2c_software related driver library.
* Date： 20201126
* Awinic_Version： aw_soc_driver_v1.0.0
*/
#include "compile_option.h"
#ifdef AW_86802

#ifndef __AW8680X_I2C_SOFTWARE_H
#define __AW8680X_I2C_SOFTWARE_H

/* Include ------------------------------------------------------------------*/
#include "aw8680x_def.h"

#define SLAVE_ADDR			(0x5C)
#define I2C_SCL_GPIO_MUX				(GPIO_PIN_MUX_4)
#define I2C_SDA_GPIO_MUX				(GPIO_PIN_MUX_5)
#define I2C_SCL_GPIO_PIN				(GPIO_PIN_4)
#define I2C_SDA_GPIO_PIN				(GPIO_PIN_5)

#define I2C_DELAY()				(__NOP())
#define I2C_DELAY1()			__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
#define I2C_DELAY2()			I2C_DELAY1();I2C_DELAY1();I2C_DELAY1();I2C_DELAY1();

#define I2C_SCL_1()			(GPIO->SWPOT_DR |= I2C_SCL_GPIO_PIN)
#define I2C_SCL_0()			(GPIO->SWPOT_DR &= ~I2C_SCL_GPIO_PIN)
#define I2C_SDA_1()			(GPIO->SWPOT_DR |= I2C_SDA_GPIO_PIN)
#define I2C_SDA_0()			(GPIO->SWPOT_DR &= ~I2C_SDA_GPIO_PIN)
#define SDA_GET_LEVEL()		((GPIO->EXT_POT & (I2C_SDA_GPIO_PIN)) ? 1 : 0)
#define SCL_GET_LEVEL()		((GPIO->EXT_POT & (I2C_SCL_GPIO_PIN)) ? 1 : 0)
#define I2C_SOFT_TIMEOUT	(11500)		// Timeout judgment 10ms.

#define I2C_RD				(1)
#define I2C_WR				(0)

#define I2C_ACK				(0)
#define I2C_NACK			(1)

#define I2C_DATABITS_MAX	(8)
#define DATA_BIT7_MASK		(0x80)
#define DATA_BIT1_MASK		(0x01)

enum i2c_ret_status {
	I2C_ERROR = 0,
	I2C_SUCCESS = 1,
};
typedef enum i2c_ret_status I2C_SOFTWARE_STATUS_E;

I2C_SOFTWARE_STATUS_E i2c_software_read_bytes(AW_U8 *p_data, AW_U16 size);
I2C_SOFTWARE_STATUS_E i2c_software_write_bytes(AW_U8 *p_data, AW_S16 size);

#endif /* AW8680X_I2C_SOFTWARE_H */
#endif